package com.hermes.biz.dao.category.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hermes.biz.common.model.category.CategoryDO;
import com.hermes.biz.dao.category.CategoryDAO;

public class CategoryDAOImpl extends SqlMapClientDaoSupport implements CategoryDAO {

    /**
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<CategoryDO> getCategoryList() {
        try {
            return this.getSqlMapClientTemplate().getSqlMapClient()
                .queryForList("getAllCategorys", null);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @param categoryName
     * @return
     */
    public CategoryDO getByCategoryName(String categoryName) {
        try {
            return (CategoryDO) this.getSqlMapClientTemplate().getSqlMapClient()
                .queryForObject("CategoryDAO.getCategoryByName", categoryName);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @param categoryId
     * @return
     */
    public CategoryDO getByCategoryId(long categoryId) {
        try {
            return (CategoryDO) this.getSqlMapClientTemplate().getSqlMapClient()
                .queryForObject("CategoryDAO.getCategoryById", categoryId);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /**
     * @param categoryDO
     */
    public void saveCategory(CategoryDO categoryDO) {
        try {
            this.getSqlMapClientTemplate().getSqlMapClient()
                .insert("CategoryDAO.insertCategory", categoryDO);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * @param categoryId
     */
    public void deleteCategory(long categoryId) {
        try {
            this.getSqlMapClientTemplate().getSqlMapClient()
                .delete("CategoryDAO.deleteCategory", categoryId);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * @param categoryDO
     */
    public void updateCategory(CategoryDO categoryDO) {
        try {
            this.getSqlMapClientTemplate().getSqlMapClient()
                .update("CategoryDAO.updateCategory", categoryDO);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
